<script type="text/javascript">
$(function(){
	var pg = App.log.logsQuery.ui, pp = pg.params;

	var frm = {
		path: pg.seek('path'),
		target: pg.seek('target'),
		addr: pg.seek('addr'),
		regx: pg.seek('regx'),
		key: pg.seek('key'),
		level: pg.seek('level'),
		thread: pg.seek('thread'),
		trace: pg.seek('trace'),
		start: pg.seek('start'),
		end: pg.seek('end'),
		limit: pg.seek('limit')
	}
	frm.path.mac('combo', {
		width: 242,
		boxWidth: 243,
		readOnly: 1,
		keyField: 'path',
		displayField: 'name',
		multiSelect: false,
		cols : [{
			field: 'path', width: 120
		}, {
			field: 'name', width: 120
		}],
		data: [{ path: '/es/index', name: 'Elasticsearch' }]
	}).val('/es/index');
	frm.level.mac('combo', {
		width: 242,
		boxWidth: 243,
		readOnly: 1,
		keyField: 'value',
		displayField: 'name',
		multiSelect: false,
		cols: [{
			field: 'name', width: '100%'
		}],
		data: [{
			name: 'ALL', value: ''
		}, {
			name: 'DEBUG', value: 'DEBUG'
		}, {
			name: 'INFO', value: 'INFO'
		}, {
			name: 'WARN', value: 'WARN'
		}, {
			name: 'ERROR', value: 'ERROR'
		}]
	}).val('');

	function getValues(){
		return {
			path: frm.path.val(),
			target: frm.target.val(),
			addr: frm.addr.val(),
			regx: frm.regx.val(),
			key: frm.key.val(),
			level: frm.level.val(),
			threadName: frm.thread.val(),
			trace: frm.trace.val(),
			startTime: frm.start.val(),
			endTime: frm.end.val(),
			pageSize: frm.limit.val()
		};
	}
	function setValues(o){
		frm.path.val(o.path || '/es/index');
		frm.target.val(o.target || 'logs');
		frm.addr.val(o.addr);
		frm.regx.val(o.regx);
		frm.key.val(o.key);
		frm.level.val(o.level || '');
		frm.thread.val(o.thread);
		frm.trace.val(o.trace);
		frm.start.val(o.start);
		frm.end.val(o.end);
		frm.limit.val(o.limit);
	}
	function validate(p){
// 		var msg=pg.seek('msg');
// 		msg.html('');
// 		var x = App.validate, v = App.soagov.validation, va = App.base.validation;
// 		return x(v.face.code, p.code, msg, '编号') &&
// 			   x(v.face.name, p.name, msg, '名称') &&
// 			   x(v.face.face, p.face, msg, '接口') &&
// 			   x(va.face.ver, p.ver, msg, '版本号');
	}
// 	$("input").blur(function(){
// 		var pms = getValues();
//  		if(!validate(pms))
//  			return;
// 	});
	pg.seek('ok').click(function(){
		var p = getValues();
		if (pg.callback) {
			pg.callback(p);
		} else {
			App.show({
				ctx: 'log',
				action: 'logsView',
				params: p
			}, $.noop, App.main);
		}
		if (pg.close) {
			pg.close();
		}
		return false;
	});
	if (pg.close) {
		pg.seek('close').click(pg.close).show();
	} else {
		pg.find('.title.hidden').show();
	}
	if (pp) {
		setValues(pp);
	}
});
</script>
<div class="title hidden">自定义日志查询</div>
<div class="form">
	<div class="item">
		<div class="label">日志存储</div>
		<div class="value">
			<div class="combo fl" name="path"></div>
		</div>
		<div class="label">日志路径</div>
		<div class="value">
			<input type="text" name="target" value="logs" />
		</div>
		<div class="clear"></div>
	</div>
	<div class="item">
		<div class="label">服务追踪号</div>
		<div class="value">
			<input type="text" name="trace" />
		</div>
		<div class="label">应用实例</div>
		<div class="value">
			<input type="text" name="addr" />
		</div>
		<div class="clear"></div>
	</div>
	<div class="item">
		<div class="label">开始时间</div>
		<div class="value">
			<input type="text" name="start" />
		</div>
		<div class="label">结束时间</div>
		<div class="value">
			<input type="text" name="end" />
		</div>
		<div class="clear"></div>
	</div>
	<div class="item">
		<div class="label">关键字</div>
		<div class="value">
			<input type="text" name="key" />
		</div>
		<div class="label">线程号</div>
		<div class="value">
			<input type="text" name="thread" />
		</div>
		<div class="clear"></div>
	</div>
	<div class="item">
		<div class="label">正则表达式</div>
		<div class="value">
			<input type="text" name="regx" />
		</div>
		<div class="label">Logger</div>
		<div class="value">
			<input type="text" name="logger" />
		</div>
		<div class="clear"></div>
	</div>
	<div class="item">
		<div class="label">日志级别</div>
		<div class="value">
			<div class="combo fl" name="level"></div>
		</div>
		<div class="label">最多返回</div>
		<div class="value">
			<input type="number" name="limit" min="200" max="2000" value="1000" step="100" />
			<span>&nbsp;行</span>
		</div>
		<div class="clear"></div>
	</div>
	<div class="item">
		<span class="label">&nbsp;</span>
		<div name="msg" class="msg" style="text-align: left;"></div>
		<div class="clear"></div>
	</div>
	<div class="bottom">
		<button name="ok">确定</button>
		&nbsp;&nbsp;
		<button name="close" class="hidden">取消</button>
	</div>
</div>